<?php
/*
 * program:	均源
 * author:	雨中漫步 & 上善若水 & qhxin
 * email:	qhxin@qhxin.com
 * date:	2014/11/11
 * description:	又是一年双十一，不能剁手，就写点东西吧~~~~~~
 */

defined('IN_SCHOOL') or die();

/*{TranslateTagBegin}*/
class model_conf extends base_model{

	//hook mod_conf_start.php
	private $table;

	function __construct() {
		//hook mod_conf_before_parent_init.php
		parent::__construct();
		$this->table = 'conf';
		//hook mod_conf_after_parent_init.php
	}

	public function get_site_conf_arr() {
		//hook mod_conf_site_conf_start.php
		return $this->get_conf_arr(1);
	}

	public function set_site_conf_arr($conf) {
		//hook mod_conf_set_site_conf_arr.php
		return $this->set_conf_arr($conf, 1);
	}
	/*
	public function get_picart_conf_arr() {
		return $this->get_conf_arr(2);
	}

	public function set_picart_conf_arr($conf) {
		return $this->set_conf_arr($conf, 2);
	}*/

	public function get_file_conf_arr() {
		//hook mod_conf_get_file_conf_arr.php
		return $this->get_conf_arr(3);
	}

	public function set_file_conf_arr($conf) {
		//hook mod_conf_set_file_conf_arr.php
		return $this->set_conf_arr($conf, 3);
	}

	public function get_misc_conf_arr() {
		//hook mod_conf_get_misc_conf_arr.php
		return $this->get_conf_arr(4);
	}

	public function set_misc_conf_arr($conf) {
		//hook mod_conf_set_misc_conf_arr.php
		return $this->set_conf_arr($conf, 4);
	}

	//===============>misc
	
	public function get_conf_arr($id) {
		//hook mod_conf_get_conf_arr.php
		$id = intval($id);
		$arr = $this->db->get( $this->table.'-id-'.$id);
		$res = core::json_decode($arr['conf']);
		return $res === FALSE ? array() : $res;
	}

	public function set_conf_arr($conf, $id = 0) {
		//hook mod_conf_set_conf_arr.php
		$id = intval($id);
		if($id == 0) {
			$id = $this->db->maxid($this->table.'-id', '+1');
		}
		$res = core::json_encode($conf);
		return $this->db->set( $this->table.'-id-'.$id, array('id'=>$id, 'conf'=> $res));
	}
	
	//hook mod_conf_end.php
}
/*{TranslateTagEnd}*/

?>